package cn.zhf.shop.controller;

import cn.zhf.shop.entity.Ad;
import cn.zhf.shop.entity.Message;
import cn.zhf.shop.service.AdService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/ad")
@Api(tags = "广告管理")
public class AdController {
    @Resource
    private AdService adService;

    @PostMapping("/append")
    @ApiOperation(value = "添加广告 服务端")
    public Message appendAd(Ad ad){
        return adService.insert(ad);
    }

    @GetMapping("/remover")
    @ApiOperation(value = "删除广告 服务端")
    public Message removeAd(int id){
        return adService.deleteByPrimaryKey(id);
    }

    @GetMapping("/update")
    @ApiOperation(value = "修改广告 服务端")
    public Message updateAd(Ad ad){
        return adService.updateByPrimaryKey(ad);
    }

    @GetMapping("/all")
    @ApiOperation(value = "获取所有广告 服务端")
    public Message<List<Ad>> getAll(){
        return adService.selectAll();
    }

    @GetMapping("/")
    @ApiOperation(value = "根据id获取广告")
    public Message<Ad> getAd(int id){
        return adService.selectByPrimaryKey(id);
    }

    @GetMapping("/ad")
    @ApiOperation(value = "获取展示的广告 客户端")
    public Message<List<Ad>> getAdShowList(){
        return adService.selectAllSelected();
    }

}
